package com.cw.auth.domain.service.impl;

import cn.dev33.satoken.secure.SaSecureUtil;
import com.cw.auth.common.enums.AuthUserStatusEnum;
import com.cw.auth.common.enums.IsDeletedFlagEnum;
import com.cw.auth.domain.convert.AuthRoleConvert;
import com.cw.auth.domain.convert.AuthUserConvert;
import com.cw.auth.domain.entity.AuthRoleBO;
import com.cw.auth.domain.entity.AuthUserBO;
import com.cw.auth.domain.service.AuthRoleDomainService;
import com.cw.auth.domain.service.AuthUserDomainService;
import com.cw.auth.infra.basic.entity.AuthRole;
import com.cw.auth.infra.basic.entity.AuthUser;
import com.cw.auth.infra.basic.service.AuthRoleService;
import com.cw.auth.infra.basic.service.AuthUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Description:
 *
 * @Author:
 * @Date: 2024/4/27 20:35
 */
@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
    @Resource
    private AuthRoleService authRoleService;

    /**
     * @author: 江传文
     * @date: 2024/4/27 21:38
     * 新增角色
     */
    @Override
    public Boolean add(AuthRoleBO authRoleBO) {
        // (BO -> Entity)
        AuthRole authRole = AuthRoleConvert.INSTANCE
                .convertBoToEntity(authRoleBO); // 通过BO转化为Entity
        authRole.setIsDeleted(IsDeletedFlagEnum.UN_DELETED.getCode()); // 设置is_deleted字段为0(未删除)
        Integer count = authRoleService.insert(authRole);

        return count > 0;
    }

    /**
     * @author: 江传文
     * @date: 2024/4/27 21:38
     * 更新角色
     */
    @Override
    public Boolean update(AuthRoleBO authRoleBO) {
        // (BO -> Entity)
        AuthRole authRole = AuthRoleConvert.INSTANCE
                .convertBoToEntity(authRoleBO); // 通过BO转化为Entity
        Integer count = authRoleService.update(authRole);

        return count > 0;
    }

    /**
     * @author: 江传文
     * @date: 2024/4/27 21:38
     * 删除角色
     */
    @Override
    public Boolean delete(AuthRoleBO authRoleBO) {
        // (BO -> Entity)
        AuthRole authRole = AuthRoleConvert.INSTANCE
                .convertBoToEntity(authRoleBO); // 通过BO转化为Entity
        authRole.setIsDeleted(IsDeletedFlagEnum.DELETED.getCode());
        Integer count = authRoleService.update(authRole);

        return count > 0;
    }

}
